$(document).ready(function() {
	

 	$("#id_region").change(function(){
              $("#id_city").load("/index/citylist", { id: ($("#id_region option:selected").val())});
              $("#id_district").load("/index/districtlist", { id: ($("#id_region option:selected").val())});

              if($("#id_region option:selected").val() > 0)
              {
              		$('#id_district').disabled = false;//attr("disabled", "false");                      
                        $("#form_koatuu").load("/index/regionkoatuu", { id: ($("#id_region option:selected").val())}, function(d){$("#form_koatuu").attr("value", d);$("#koatuu").attr("value", $("#form_koatuu").val());});
                                        
              }
              else
              {
                  
              	$("#id_city").attr("disabled", "disabled");
              	$('#id_district').attr("disabled", "disabled");
                if($("#role_id option:selected").val() != 1){
                    $("#form_koatuu").attr("value", '9999999999');
                    $("#koatuu").attr("value", '9999999999');    
                }else{
                    $("#form_koatuu").attr("value", '0000000000');
                    $("#koatuu").attr("value", '0000000000');
                }
                
              };
              
    });
    
    $("#id_district").change(function(){
          $("#id_city").load("/index/citylist", { 
                    id_district: ($("#id_district option:selected").val()), 
                    id: ($("#id_region option:selected").val())
          });      
          if($("#id_district option:selected").val() > 0)
          {
                    $("#id_city").disabled = false;//attr("disabled", "")
                    $("#form_koatuu").load("/index/districtkoatuu", { id: ($("#id_district option:selected").val())}, function(d){$("#form_koatuu").attr("value", d);$("#koatuu").attr("value", $("#form_koatuu").val());});
          }
          else
          {
            $("#id_city").attr("disabled", "disabled")
            $("#form_koatuu").load("/index/regionkoatuu", { id: ($("#id_region option:selected").val())}, function(d){$("#form_koatuu").attr("value", d);$("#koatuu").attr("value", $("#form_koatuu").val());});
          };
              
    });    
    $("#form_koatuu").change(function(){
              $("#koatuu").attr("value", $("#form_koatuu").val());
    });  
    
});